//
//  RJTools.m
//  AirQuality
//
//  Created by Po on 15/3/11.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJTools.h"

@implementation RJTools


+ (CGRect)getReSizeRect:(CGRect)rect size:(CGFloat)size
{
    rect.origin.x -= size;
    rect.origin.y -= size;
    rect.size.width += 2 * size;
    rect.size.height += 2 * size;
    return rect;
}

+ (NSString *)getTimeWithFormat:(NSString *)format
{
    return [self getTimeWithFormat:format time:[NSDate date]];
}

+ (NSUInteger)getDayWithStartDay:(NSDate *)startDate endDay:(NSDate *)endDay
{
    NSDate * startTime;
    NSDate * endTime;
    NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    [gregorian setFirstWeekday:2];
    [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&startTime interval:NULL forDate:startDate];
    [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&endTime interval:NULL forDate:endDay];
    NSDateComponents * dayComponent = [gregorian components:NSCalendarUnitDay fromDate:startDate toDate:endTime options:0];
    return dayComponent.day;
}

+ (NSString *)getTimeWithFormat:(NSString *)format time:(NSDate *)date
{
    NSDateFormatter * formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:format];
    return [formater stringFromDate:date];
}

+ (BOOL)isNumberString:(NSString *)string
{
    if( ![self isPureInt:string] || ![self isPureFloat:string]){
        return NO;
    }

    return YES;
}

+ (void)showMsg:(NSString *)msg time:(CGFloat)time
{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    [view setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
    
    //信息Label
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(20, ScreenHeight / 2 - 20, ScreenWidth - 40, 40)];
    [label setBackgroundColor:[UIColor whiteColor]];
    [label setText:msg];
    [label setTextColor:[UIColor blackColor]];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setFont:[UIFont systemFontOfSize:16]];
    [view addSubview:label];
    [sysWindow addSubview:view];
    [self performSelector:@selector(removeMsgView:) withObject:view afterDelay:time];
}

+ (void)showTitle:(NSString *)title msg:(NSString *)msg cancelString:(NSString *)cancelString vc:(UIViewController *)vc
{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * okAction= [UIAlertAction actionWithTitle:cancelString style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:okAction];
    [vc presentViewController:alert animated:YES completion:nil];
}

+ (void)showTitle:(NSString *)title msg:(NSString *)msg cancelString:(NSString *)cancelString confirmString:(NSString *)confirmString confirmBlock:(void(^)(void))confirmBlock vc:(UIViewController *)vc
{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * cancel = [UIAlertAction actionWithTitle:cancelString style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction * retry = [UIAlertAction actionWithTitle:confirmString style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        confirmBlock();
    }];
    [alert addAction:cancel];
    [alert addAction:retry];
    [vc presentViewController:alert animated:YES completion:nil];
}

+ (NetworkStatus)checkNetStatus
{
    return [[Reachability reachabilityForLocalWiFi] currentReachabilityStatus];
}

+(UIImage *)getImageFromView:(UIView *)view
{
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

+ (NSString *)getPinyinOfString:(NSString *)string
{
    NSMutableString *source = [string mutableCopy];
    CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO);
    return [source stringByReplacingOccurrencesOfString:@" " withString:@""];
}
+ (NSMutableAttributedString *)getPMString:(NSString *)string
{
    
    NSMutableAttributedString * attr = [[NSMutableAttributedString alloc] initWithString:string];
    [attr addAttribute:NSBaselineOffsetAttributeName
                 value:[NSNumber numberWithFloat:-3]
                 range:NSMakeRange(2, 3)];
    [attr addAttribute:NSFontAttributeName
                 value:[UIFont systemFontOfSize:10]
                 range:NSMakeRange(2, 3)];
    [attr addAttribute:NSForegroundColorAttributeName
                 value:GetRGBColor(85, 85, 85, 1)
                 range:NSMakeRange(0, 5)];

    return attr;
}

#pragma mark - 辅助方法
+ (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

+ (BOOL)isPureFloat:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
}

+ (void)removeMsgView:(UIView *)view
{
    [view removeFromSuperview];
}

/**获取对应规则的数值*/
+ (NSUInteger)getAQIMathNumber:(NSUInteger)number
{
    if (number <= 50) {
        return 10;
    } else if (number <= 100) {
        return 15;
    } else if (number <= 150) {
        return 20;
    } else if (number <= 300) {
        return 25;
    } else {
        return 30;
    }
}

/**获取AQI污染等级*/
+ (NSString *)getRankWithNumber:(NSUInteger)num
{
    if (num <= 50) {
        return @"优";
    } else if (num <= 100) {
        return @"良";
    } else if (num <= 150) {
        return @"轻度污染";
    } else if (num <= 200) {
        return @"中度污染";
    } else if (num <= 300) {
        return @"重度污染";
    } else {
        return @"严重污染";
    }
}

/**获取缩写对应全称*/
+ (NSString *)getQulityString:(NSString *)type
{
    NSDictionary * dic = @{
                           @"  PM2.5":@"细颗粒物(PM2.5)",
                           @"  O3":@"臭氧8小时",
                           @"  SO2":@"二氧化硫",
                           @"  NO2":@"二氧化氮",
                           @"  CO":@"一氧化碳",
                           @"  PM10":@"颗粒物(PM10)",
                           @"  无":@"无"};
    return dic[type];
}

+ (NSArray *)getColorArrayWithAlpha:(CGFloat)alpha
{
    NSArray * colors = @[
                         GetRGBColor(0, 228, 0, alpha),
                         GetRGBColor(255, 185, 15, alpha),
                         GetRGBColor(255, 126, 0, alpha),
                         GetRGBColor(255, 0, 0, alpha),
                         GetRGBColor(153, 0, 76, alpha),
                         GetRGBColor(126, 0, 35, alpha),
                         GetRGBColor(164, 164, 166, alpha)
                         ];
    return colors;
}

+ (UIColor *)getColorWithAirNum:(NSInteger)num
{
    if (num > 10000) {
        return GetRGBColor(150, 150, 150, 0.6);
    }
    
    NSUInteger rank = num / 50;
    if (rank > 5) {
        return [self getColorArrayWithAlpha:0.6][5];
    }
    
    if (num % 50 == 0) {
        rank -- ;
    }
    if (num == 50) {
        ;
    }
    return [self getColorArrayWithAlpha:0.6][rank];
}
+ (UIColor *)getColorWithAirNum1:(CGFloat)num type1:(NSString *)type alpha1:(CGFloat)alpha
{
    NSUInteger rank = [self getRankWithType1:type num1:num];
    if (rank != -1) {
        return [self getColorArrayWithAlpha:alpha][rank];
    } else {
        return GetRGBColor(150, 150, 150, 0.6);
    }
}

+ (UIColor *)getColorWithAirNum:(CGFloat)num type:(NSString *)type alpha:(CGFloat)alpha
{
    NSUInteger rank = [self getRankWithType:type num:num];
    if (rank != -1) {
        return [self getColorArrayWithAlpha:alpha][rank];
    } else {
        return GetRGBColor(150, 150, 150, 0.6);
    }
}
/**
 *  根据I值得到颜色值
 *
 *  @param num I值
 *
 *  @return 颜色
 */
+ (UIColor *)getColorWithAirINum:(CGFloat)num
{
    NSInteger rank = num/50;
    NSArray * colors = @[
                         GetRGBColor(0, 228, 0, 1),
                         GetRGBColor(255, 185, 15, 1),
                         GetRGBColor(255, 126, 0, 1),
                         GetRGBColor(255, 0, 0, 1),
                         GetRGBColor(153, 0, 76, 1),
                         GetRGBColor(126, 0, 35, 1),
                         GetRGBColor(164, 164, 166, 1)
                         ];
    if (rank >= 6 ) {
        return colors[6];
    }
    return colors[rank];
}

+ (UIColor *)getNewColorWithAirNum:(CGFloat)num type:(NSString *)type alpha:(CGFloat)alpha
{
    NSUInteger rank = [self getRankWithType:type num:num];
    if (rank == 1) {
        return GetRGBColor(253, 198, 30, 1);
    } else if (rank != -1){
        return [self getColorArrayWithAlpha:alpha][rank];
    } else {
        return GetRGBColor(150, 150, 150, 0.6);
    }
}
+ (NSUInteger)getRankWithType1:(NSString *)type num1:(CGFloat)num
{
    if ([type isEqualToString:@"AQI"]) {
        NSInteger rank = (num / 50);
        if (rank>=5) {
            return 5;
        }else{
            return rank;
        }
        //        if (rank <= 6) {
        //            if ((NSInteger)num % 50 == 0) {
        //                return rank -1;
        //            }
        //            return rank;
        //        } else {
        //            return 6;
        //        }
    } else if([type isEqualToString:@"SO2"]) {
        if (num <= 50) {
            return 0;
        } else if (num <= 150) {
            return 1;
        } else if (num <= 500) {
            return 2;
        } else if (num <= 650) {
            return 3;
        }else{
            return 4;
        }
    } else if ([type isEqualToString:@"NO2"]) {
        if (num <= 100) {
            return 0;
        } else if (num <= 200) {
            return 1;
        } else if (num <= 700) {
            return 2;
        } else if (num <= 1200) {
            return 3;
        } else if (num <= 2340) {
            return 4;
        } else if (num <= 3090) {
            return 5;
        } else{
            return 5;
        }
    } else if ([type isEqualToString:@"CO"]) {
        if (num <= 5) {
            return 0;
        } else if (num <= 10) {
            return 1;
        } else if (num <= 35) {
            return 2;
        } else if (num <= 60) {
            return 3;
        } else if (num <= 90) {
            return 4;
        } else if (num <= 120) {
            return 5;
        } else{
            return 5;
        }
    } else if ([type isEqualToString:@"O3"]) {
        if (num <= 160) {
            return 0;
        } else if (num <= 200) {
            return 1;
        } else if (num <= 300) {
            return 2;
        } else if (num <= 400) {
            return 3;
        } else if (num <= 800) {
            return 4;
        } else if (num <= 1000) {
            return 5;
        } else{
            return 5;
        }
    } else if ([type isEqualToString:@"PM2_5"] || [type isEqualToString:@"PM2.5"]) {
        if (num <= 35) {
            return 0;
        } else if (num <= 75) {
            return 1;
        } else if (num <= 115) {
            return 2;
        } else if (num <= 150) {
            return 3;
        } else if (num <= 250) {
            return 4;
        } else if (num <= 350) {
            return 5;
        } else {
            return 5;
        }
    } else if ([type isEqualToString:@"PM10"]) {
        if (num <= 50) {
            return 0;
        } else if (num <= 150) {
            return 1;
        } else if (num <= 250) {
            return 2;
        } else if (num <= 350) {
            return 3;
        } else if (num <= 420) {
            return 4;
        } else if (num <= 500) {
            return 5;
        } else {
            return 5;
        }
    }
    return -1;
}
/**
 *  返回等级
 *
 *  @param num I值
 *
 *  @return 等级
 */
+ (NSUInteger)getRankWithNum:(CGFloat)num
{
    NSInteger rank = num/50;
    if (rank >= 6) {
        return 6;
    }
    return rank;
}

+ (NSUInteger)getRankWithType:(NSString *)type num:(CGFloat)num
{
    if ([type isEqualToString:@"AQI"]) {
        if (num <= 50) {
            return 0;
        }else if (num <= 100)
        {
            return 1;
        }else if (num <= 150){
            return 2;
        }else if (num <= 200){
            return 3;
        }else if (num <= 300){
            return 4;
        }else{
            return 5;
        }
    } else if([type isEqualToString:@"SO2"]||[type isEqualToString:@"SO₂"]) {
        if (num <= 150) {
            return 0;
        } else if (num <= 500) {
            return 1;
        } else if (num <= 650) {
            return 2;
        } else if (num <= 800) {
            return 3;
        }
    } else if ([type isEqualToString:@"NO2"] || [type isEqualToString:@"NO₂"]) {
        if (num <= 100) {
            return 0;
        } else if (num <= 200) {
            return 1;
        } else if (num <= 700) {
            return 2;
        } else if (num <= 1200) {
            return 3;
        } else if (num <= 2340) {
            return 4;
        } else if (num <= 3090) {
            return 5;
        } else if (num <= 3840) {
            return 6;
        }
    } else if ([type isEqualToString:@"CO"]) {
        if (num <= 5) {
            return 0;
        } else if (num <= 10) {
            return 1;
        } else if (num <= 35) {
            return 2;
        } else if (num <= 60) {
            return 3;
        } else if (num <= 90) {
            return 4;
        } else if (num <= 120) {
            return 5;
        } else if (num <= 150) {
            return 6;
        }
    } else if ([type isEqualToString:@"O3"]||[type isEqualToString:@"O₃"]) {
        if (num <= 160) {
            return 0;
        } else if (num <= 200) {
            return 1;
        } else if (num <= 300) {
            return 2;
        } else if (num <= 400) {
            return 3;
        } else if (num <= 800) {
            return 4;
        } else if (num <= 1000) {
            return 5;
        } else if (num <= 1200) {
            return 6;
        }
    } else if ([type isEqualToString:@"PM2_5"] || [type isEqualToString:@"PM2.5"]| [type isEqualToString:@"PM"]) {
        if (num <= 35) {
            return 0;
        } else if (num <= 75) {
            return 1;
        } else if (num <= 115) {
            return 2;
        } else if (num <= 150) {
            return 3;
        } else if (num <= 250) {
            return 4;
        } else if (num <= 350) {
            return 5;
        } else if (num <= 500) {
            return 6;
        }
    } else if ([type isEqualToString:@"PM10"]||[type isEqualToString:@"PM₁₀"]) {
        if (num <= 50) {
            return 0;
        } else if (num <= 150) {
            return 1;
        } else if (num <= 250) {
            return 2;
        } else if (num <= 350) {
            return 3;
        } else if (num <= 420) {
            return 4;
        } else if (num <= 500) {
            return 5;
        } else if (num <= 600) {
            return 6;
        }
    }
    return -1;
}

+ (NSArray *)getTrueCellTitleWithKeys:(NSArray *)keys
{
    NSMutableArray * titleArray = [NSMutableArray array];
    for (NSString * key in keys) {
        [titleArray addObject:[self getTrueTypeTitlleWithCellKey:key]];
    }
    return titleArray;
}

+ (NSString *)getTrueTypeTitlleWithCellKey:(NSString *)key
{
    if ([key isEqualToString:@"pm2_5"]) {
        return @"PM2.5";
    } else if ([key isEqualToString:@"pm10"]) {
        return @"PM10";
    } else if ([key isEqualToString:@"o3"]) {
        return @"O3";
    } else if ([key isEqualToString:@"so2"]) {
        return @"SO2";
    } else if ([key isEqualToString:@"no2"]) {
        return @"NO2";
    } else if ([key isEqualToString:@"aqi"]){
        return @"AQI";
    } else {
        return @"CO";
    }
}

+ (NSArray *)getKeysArrayWithTitles:(NSArray *)titles
{
    NSMutableArray * keysArray = [NSMutableArray array];
    for (NSString * title in titles) {
        [keysArray addObject:[self getTrueKeyTitlleWithTitle:title]];
    }
    return keysArray;
}

+ (NSArray *)getTitlesArrayWithKeys:(NSArray *)keys
{
    NSMutableArray * titlesArray = [NSMutableArray array];
    for (NSString * title in keys) {
        [titlesArray addObject:[self getTrueTypeTitlleWithCellKey:title]];
    }
    return titlesArray;
}

+ (NSString *)getTrueKeyTitlleWithTitle:(NSString *)title
{
    if ([title isEqualToString:@"PM2.5"] || [title isEqualToString:@"PM2_5"]) {
        return @"pm2_5";
    } else if ([title isEqualToString:@"PM10"]) {
        return @"pm10";
    } else if ([title isEqualToString:@"O3"]) {
        return @"o3";
    } else if ([title isEqualToString:@"SO2"]) {
        return @"so2";
    } else if ([title isEqualToString:@"NO2"]) {
        return @"no2";
    } else if ([title isEqualToString:@"AQI"]){
        return @"aqi";
    } else {
        return @"co";
    }
}


+ (NSUInteger)getPM25MathNum:(CGFloat)num
{
    if (num <= 35) {
        return 5;
    } else if (num <= 75) {
        return 10;
    } else if (num <= 150) {
        return 15;
    } else if (num <= 350) {
        return 20;
    } else {
        return 30;
    }
}

/**计算AQI区间*/
+ (NSUInteger)getAQINumber:(CGFloat)data
{
    CGFloat nHigh, nLow, nHighAQI, nLowAQI;
    nHigh = 0;
    nLow = 0;
    nHighAQI = 0;
    nLowAQI = 0;
    if(data>=0 && data<=35){
        nHigh=35;
        nLow=0;
        nHighAQI=50;
        nLowAQI=0;
    }else if(data>35 && data<=75){
        nHigh=75;
        nLow=35;
        nHighAQI=100;
        nLowAQI=50;
    }else if(data>75 && data<=115){
        nHigh=115;
        nLow=75;
        nHighAQI=150;
        nLowAQI=100;
    }else if(data>115 && data<=150){
        nHigh=150;
        nLow=115;
        nHighAQI=200;
        nLowAQI=150;
    }else if(data>150 && data<=250){
        nHigh=250;
        nLow=150;
        nHighAQI=300;
        nLowAQI=200;
    }else if(data>250 && data<=350){
        nHigh=350;
        nLow=250;
        nHighAQI=400;
        nLowAQI=300;
    }else if(data>350 && data<=500){
        nHigh=500;
        nLow=350;
        nHighAQI=500;
        nLowAQI=400;
    }else if(data>500){
        return -1;
    }
    CGFloat num= (nHighAQI - nLowAQI) * (data - nLow) / (nHigh - nLow) + nLowAQI;
    if (num - (NSInteger)num > 0) {
        num ++;
    }
    return num;
}

+ (CGSize)reSetSize:(CGSize)size width:(CGFloat)width
{
    CGSize imageSize = size;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    //缩放图片大小适应屏幕
    imageSize.height *= (width / imageSize.width);
    imageSize.width = width;
    if (height < imageSize.height) {
        imageSize.height *= (height / imageSize.height);
        imageSize.width = height;
    }
    return imageSize;
}

+ (NSArray *)getLineColors
{
    return @[
             GetRGBColor(138, 28, 189, 1),
             GetRGBColor(111, 197, 71, 1),
             GetRGBColor(251, 126, 10, 1),
             GetRGBColor(227, 0, 0, 1),
             GetRGBColor(49, 49, 49, 1),
             GetRGBColor(255, 0, 255, 1),
             GetRGBColor(153, 108, 51, 1),
             GetRGBColor(0, 51, 204, 1),
             [UIColor redColor],
             [UIColor blueColor],
             [UIColor yellowColor],
             [UIColor orangeColor],
             [UIColor blackColor],
             [UIColor purpleColor],
             [UIColor greenColor],
             [UIColor grayColor],
             [UIColor cyanColor],
             [UIColor magentaColor],
             GetRGBColor(200, 200, 100, 1),
             GetRGBColor(100, 100, 200, 1),
             GetRGBColor(50, 100, 150, 1)
             ];
    
}

+ (NSArray *)returnRankWithType:(NSString *)type num:(CGFloat)num
{
    CGFloat proportion = (CGFloat)((NSInteger)num%50)/50;
    NSUInteger rank = num / 50;
    return @[@(rank),@(proportion)];
   
    if ([type isEqualToString:@"AQI"]) {
        NSUInteger rank = (num / 50);
        proportion = num/50;
        if (rank <= 6) {
            if ((NSInteger)num % 50 == 0) {
                return @[@(rank -1),@(proportion)];
                //                return rank -1;
            }
            return @[@(rank),@(proportion)];
            //            return rank;
        } else {
            return @[@(6),@(proportion)];
            //            return 6;
        }
    } else if([type isEqualToString:@"SO2"]) {
        if (num <= 150) {
            proportion = num/150;
            return @[@(0),@(proportion)];
            //            return 0;
        } else if (num <= 500) {
            proportion = num/500;
            return @[@(1),@(proportion)];
            //            return 1;
        } else if (num <= 650) {
            proportion = num/650;
            return @[@(2),@(proportion)];
            //            return 2;
        } else if (num <= 800) {
            proportion = num/800;
            return @[@(3),@(proportion)];
            //            return 3;
        }
    } else if ([type isEqualToString:@"NO2"]) {
        if (num <= 100) {
            proportion = num/100;
            return @[@(0),@(proportion)];
            //            return 0;
        } else if (num <= 200) {
            proportion = num/200;
            return @[@(1),@(proportion)];
            //            return 1;
        } else if (num <= 700) {
            proportion = num/700;
            return @[@(2),@(proportion)];
            //            return 2;
        } else if (num <= 1200) {
            proportion = num/1200;
            return @[@(3),@(proportion)];
            //            return 3;
        } else if (num <= 2340) {
            proportion = num/2340;
            return @[@(4),@(proportion)];
            //            return 4;
        } else if (num <= 3090) {
            proportion = num/3090;
            return @[@(5),@(proportion)];
            //            return 5;
        } else if (num <= 3840) {
            proportion = num/3840;
            return @[@(6),@(proportion)];
            //            return 6;
        }
    } else if ([type isEqualToString:@"CO"]) {
        if (num <= 5) {
            proportion = num/5;
            return @[@(0),@(proportion)];
            //            return 0;
        } else if (num <= 10) {
            proportion = num/10;
            return @[@(1),@(proportion)];
            //            return 1;
        } else if (num <= 35) {
            proportion = num/35;
            return @[@(2),@(proportion)];
            //            return 2;
        } else if (num <= 60) {
            proportion = num/60;
            return @[@(3),@(proportion)];
            //            return 3;
        } else if (num <= 90) {
            proportion = num/90;
            return @[@(4),@(proportion)];
            //            return 4;
        } else if (num <= 120) {
            proportion = num/120;
            return @[@(5),@(proportion)];
            //            return 5;
        } else if (num <= 150) {
            proportion = num/150;
            return @[@(6),@(proportion)];
            //            return 6;
        }
    } else if ([type isEqualToString:@"O3"]) {
        if (num <= 160) {
            proportion = num/160;
            return @[@(0),@(proportion)];
            //            return 0;
        } else if (num <= 200) {
            proportion = num/200;
            return @[@(1),@(proportion)];
            //            return 1;
        } else if (num <= 300) {
            proportion = num/300;
            return @[@(2),@(proportion)];
            //            return 2;
        } else if (num <= 400) {
            proportion = num/400;
            return @[@(3),@(proportion)];
            //            return 3;
        } else if (num <= 800) {
            proportion = num/800;
            return @[@(4),@(proportion)];
            //            return 4;
        } else if (num <= 1000) {
            proportion = num/1000;
            return @[@(5),@(proportion)];
            //            return 5;
        } else if (num <= 1200) {
            proportion = num/1200;
            return @[@(6),@(proportion)];
            //            return 6;
        }
    } else if ([type isEqualToString:@"PM2_5"] || [type isEqualToString:@"PM2.5"]) {
        if (num <= 35) {
            proportion = num/35;
            return @[@(0),@(proportion)];
            //            return 0;
        } else if (num <= 75) {
            proportion = num/75;
            return @[@(1),@(proportion)];
            //            return 1;
        } else if (num <= 115) {
            proportion = num/115;
            return @[@(2),@(proportion)];
            //            return 2;
        } else if (num <= 150) {
            proportion = num/150;
            return @[@(3),@(proportion)];
            //            return 3;
        } else if (num <= 250) {
            proportion = num/250;
            return @[@(4),@(proportion)];
            //            return 4;
        } else if (num <= 350) {
            proportion = num/350;
            return @[@(5),@(proportion)];
            //            return 5;
        } else if (num <= 500) {
            proportion = num/500;
            return @[@(6),@(proportion)];
            //            return 6;
        }
    } else if ([type isEqualToString:@"PM10"]) {
        if (num <= 50) {
            proportion = num/50;
            return @[@(0),@(proportion)];
            //            return 0;
        } else if (num <= 150) {
            proportion = num/150;
            return @[@(1),@(proportion)];
            //            return 1;
        } else if (num <= 250) {
            proportion = num/250;
            return @[@(2),@(proportion)];
            //            return 2;
        } else if (num <= 350) {
            proportion = num/350;
            return @[@(3),@(proportion)];
            //            return 3;
        } else if (num <= 420) {
            proportion = num/420;
            return @[@(4),@(proportion)];
            //            return 4;
        } else if (num <= 500) {
            proportion = num/500;
            return @[@(5),@(proportion)];
            //            return 5;
        } else if (num <= 600) {
            proportion = num/600;
            return @[@(6),@(proportion)];
            //            return 6;
        }
    }
    proportion = 1;
    return @[@(-1),@(proportion)];
    //    return -1;
}

+ (NSArray *)getCstationColors{
    
    return @[
             [UIColor clearColor],
             [UIColor redColor],
             SysMainColor
             ];
}

+ (CGFloat)getCityCenterLatitudeWithCityName:(NSString *)cityName withLatitude:(CGFloat)latitude
{
    if ([cityName isEqualToString:@"达州"]) {
        return latitude+0.02;
    }if ([cityName isEqualToString:@"南充"]) {
        return  latitude-0.04;
    }
    if ([cityName isEqualToString:@"广安"]) {
        return  latitude +0.05;
    }
    if ([cityName isEqualToString:@"泸州"]) {
        return  latitude +0.04;
    }
    if ([cityName isEqualToString:@"眉山"]) {
        return  latitude - 0.02;
    }
    if ([cityName isEqualToString:@"遂宁"]) {
        //        latitude -= 0.02;
        //        longitude += 0.05;
        return latitude-0.02;
    }
    if ([cityName isEqualToString:@"雅安"]) {
        //        latitude -= 0.03;
        //        longitude -= 0.03;
        return latitude-0.03;
    }
    return latitude;
}

+ (CGFloat)getCityCenterLatitudeWithCityName:(NSString *)cityName withLongtitude:(CGFloat)longtitude
{
    if ([cityName isEqualToString:@"遂宁"]) {
        //        latitude -= 0.02;
        //        longitude += 0.05;
        return longtitude+0.05;
    }
    if ([cityName isEqualToString:@"雅安"]) {
        //        latitude -= 0.03;
        //        longitude -= 0.03;
        return longtitude-0.03;
    }
    return longtitude;
}

+ (CGFloat)getLatitudeWithCityName:(NSString *)cityName withLatitude:(CGFloat)latitude
{
    
    //    if ([cityName isEqualToString:@"苏山坪"]) {
    //        return <#expression#>
    //        coor.latitude = [columns[@"LAT"] floatValue]+0.04;
    //        coor.longitude = [columns[@"LNG"] floatValue]+0.05;
    //    }
    if ([cityName isEqualToString:@"市政中心"]) {
        return latitude+0.06;
        //        coor.latitude = [columns[@"LAT"] floatValue]+0.06;
    }
    if ([cityName isEqualToString:@"东山公园"]) {
        return latitude+0.04;
        //        coor.latitude = [columns[@"LAT"] floatValue]+
        //        0.04;
    }
    if ([cityName isEqualToString:@"西山风景区"]) {
        return latitude+0.04;
        //        coor.latitude = [columns[@"LAT"] floatValue]+
        //        0.04;
    }
    if ([cityName isEqualToString:@"南充炼油厂"]) {
        return latitude+0.04;
        //        coor.latitude = [columns[@"LAT"] floatValue]+
        //        0.04;
    }
    if ([cityName isEqualToString:@"莲花山"]) {
        return latitude+0.05;
        //        coor.latitude = [columns[@"LAT"] floatValue]+0.05;
    }
    if ([cityName isEqualToString:@"黄金嘴"]) {
        return latitude-0.04;
        //        coor.latitude = [columns[@"LAT"] floatValue]-0.04;
    }if ([cityName isEqualToString:@"兰田宪桥"]) {
        return latitude+0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.07;
    }
    if ([cityName isEqualToString:@"市政府"]) {
        return latitude+0.05;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.05;
    }
    if ([cityName isEqualToString:@"炳草岗"]) {
        return latitude+0.05;
        //        coor.latitude = [columns[@"LAT"] floatValue]+0.05;
    }
    if ([cityName isEqualToString:@"三水厂"]) {
        return latitude+0.05;
        //        coor.latitude = [columns[@"LAT"] floatValue]-
        //        0.05;
    }
    if ([cityName isEqualToString:@"南充市委"]) {
        return latitude-0.02;
        //        coor.latitude = [columns[@"LAT"] floatValue];
    }
    if ([cityName isEqualToString:@"高坪区监测站"	]) {
        return latitude-0.02;
        //        coor.latitude = [columns[@"LAT"] floatValue];
    }
    
    return latitude;
}

+ (CGFloat)getLatitudeWithCityName:(NSString *)cityName withLongtitude:(CGFloat)longtitude
{
    if ([cityName isEqualToString:@"区法院"]) {
        return longtitude-0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]-0.07;
    }
    if ([cityName isEqualToString:@"四十中小"]) {
        return longtitude+0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.07;
    }
    if ([cityName isEqualToString:@"嘉陵区环保局"]) {
        return longtitude+0.08;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.08;;
    }
    if ([cityName isEqualToString:@"乐山大佛景区"]) {
        return longtitude+0.04;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.04;
    }
    if ([cityName isEqualToString:@"广电花园"]) {
        return longtitude+0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.07;
    }
    if ([cityName isEqualToString:@"檀木林街"]) {
        return longtitude+0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.07;
    }
    if ([cityName isEqualToString:@"宜宾四中"]) {
        return longtitude+0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.07;
    }
    if ([cityName isEqualToString:@"市环境监测站"]) {
        return longtitude+0.04;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.04;
    }
    //    if ([cityName isEqualToString:@"灵岩寺"]) {
    //        coor.latitude = [columns[@"LAT"] floatValue]-0.3;
    //        coor.longitude = [columns[@"LNG"] floatValue]+0.32;
    //    }
    if ([cityName isEqualToString:@"川农大"]) {
        return longtitude+0.05;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.05;
    }
    if ([cityName isEqualToString:@"内江日报社"]) {
        return longtitude-0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]-0.07;
    }
    if ([cityName isEqualToString:@"市政府"]) {
        return longtitude-0.07;
        //        coor.longitude = [columns[@"LNG"] floatValue]+0.07;
    }
    return longtitude;
}

+ (UIColor *)toolGetColorByIaqi:(NSString *)iValue
{
    NSInteger rank = [iValue floatValue]/50;
    if (rank >= 6) {
        rank = 6;
    }
    NSArray * colors = @[
                         GetRGBColor(0, 228, 0, 1),
                         GetRGBColor(255, 185, 15, 1),
                         GetRGBColor(255, 126, 0, 1),
                         GetRGBColor(255, 0, 0, 1),
                         GetRGBColor(153, 0, 76, 1),
                         GetRGBColor(126, 0, 35, 1),
                         GetRGBColor(164, 164, 166, 1)
                         ];
    return colors[rank];
}
@end

